using System;
using System.Globalization;
using Avalonia.Data.Converters;
using AvaloniaWeChatList.Models;

namespace AvaloniaWeChatList.Convertors;

public sealed class ChatMsgVisibleConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value is bool and false;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter,
        CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

public sealed class ChatTypeGroupConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not ChatItemModel model)
            return false;

        if (parameter is not string group)
            return false;

        var type = model.ChatType;

        if (bool.TryParse(group, out var isGroup) && isGroup)
        {
            return type == ChatType.Group;
        }
        else
        {
            return type == ChatType.Default;
        }
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter,
        CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

public sealed class ChatTypeConverter1 : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not ChatItemModel model)
            return false;

        var type = model.ChatType;

        if (type == ChatType.Group)
            return true;

        return false;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter,
        CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

public sealed class ChatTypeConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return true;
        if (value is null)
            return false;

        var type = (ChatType)value;

        if (type == ChatType.App)
            return true;

        return false;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter,
        CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}